package cn.com.web.Servlet;

import cn.com.domain.Student;
import cn.com.service.StudentService;
import cn.com.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/StudentListServlet")
public class StudentListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //调用StudentService完成查询
        StudentService studentService=new StudentServiceImpl();
        List<Student> students = studentService.findAll();
        //将list存入域
        request.setAttribute("students",students);

        //转发到studentmessage.jsp
        request.getRequestDispatcher("studentmessage.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
